package com.example.pungolo.journal.view;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.example.pungolo.journal.EntryActivity;
import com.example.pungolo.journal.R;
import com.example.pungolo.journal.model.DiaryEntry;
import com.example.pungolo.journal.model.Mood;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class DiaryEntryView extends LinearLayout {
  private DiaryEntry entry;
  private TextView entryTextView;
  private TextView entryDateTextView;
  private ImageView entryMoodIcon;

  public DiaryEntryView(Context context) {
    super(context);
    init();
  }

  public DiaryEntryView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  @SuppressLint("NewApi")
  public DiaryEntryView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
  }

  private void init() {
    Context context = this.getContext();
    this.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    View.inflate(context, R.layout.diary_entry_view, this);

    this.entryMoodIcon = (ImageView) findViewById(R.id.entry_mood_icon);
    this.entryTextView = (TextView) findViewById(R.id.entry_text);
    this.entryDateTextView = (TextView) findViewById(R.id.entry_date);
    // Todo: usare un 9-patch per lo sfondo di questi entry
  }

  @Override
  protected ContextMenuInfo getContextMenuInfo() {
    return entry;
  }

  public void setEntry(DiaryEntry entry) {
    if (entry != null) {
      this.entryTextView.setText(entry.getText());
      this.entryMoodIcon.setImageResource(entry.getMood().res);
      String timeString = SimpleDateFormat.getTimeInstance().format(entry.getDate());
      this.entryDateTextView.setText(timeString);
    }
    this.entry = entry;
  }

  public DiaryEntry getEntry() {
    return entry;
  }
}
